package com.jiepos.mpos.biz.appInfM.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.appInfM.service.MessageInfService;
import com.jiepos.mpos.common.entity.App_Custom_InfEntity;
import com.jiepos.mpos.common.entity.App_Ins_InfEntity;
import com.jiepos.mpos.common.entity.App_Message_InfEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;

/**
 *
 *
 * <p>标题: —— 系统参数控制器</p>
 * <p>模块: 通用平台</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @author 余翼膑
 * @version 1.0
 * @since 2017年9月30日
 * @history（历次修订内容、修订人、修订时间等）
 */
@Controller
@RequestMapping("messageInf")
public class MessageInfController extends BaseController {
    @Autowired
    private MessageInfService messageInfService;

    /**
     * 进入通知公告页面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getNoticeList.do")
    public ModelAndView getNoticeList(HttpServletRequest request, HttpServletResponse response, Pagination pagination){

        ModelAndView model = new ModelAndView("/module/appInfM/messageInf/notice_list");
        return super.getDetail(request, response, model);
    }
    /**
     * 查询通知公告列表信息json数据
     * @param pagination
     * @param appMessageInfEntity
     * @return
     */
    @RequestMapping("/noticeListJson.do")
    public @ResponseBody
    Map getNoticeListJson(HttpServletRequest request, Pagination pagination, App_Message_InfEntity appMessageInfEntity,App_Ins_InfEntity appInsInfEntity){
        return messageInfService.getNoticeList(request,pagination, appMessageInfEntity,appInsInfEntity);
    }
    /**
     * 进入通知公告详细页面
     * @param request
     * @param response
     * @param pagination
     * @param message_uuid
     * @return
     */
    @RequestMapping("/getNoticeDetail.do")
    public ModelAndView getNoticeDetail(HttpServletRequest request, HttpServletResponse response,
                                              Pagination pagination,String message_uuid) {
        ModelAndView model = new ModelAndView("/module/appInfM/messageInf/notice_detail");
        // 菜单编码
        Map infEntity = messageInfService.getNoticeById(message_uuid);
        model.addObject("infEntity", infEntity);
        return super.getDetail(request, response, model);
    }
    /**
     * 保存通知公告信息
     * @param request
     * @param response
     * @param appMessageInfEntity
     * @return
     */
    @RequestMapping("/saveNoticeDetail.do")
    public ModelAndView saveNoticeDetail(HttpServletRequest request, HttpServletResponse response, App_Message_InfEntity appMessageInfEntity) {

        messageInfService.saveNotice(appMessageInfEntity, super.getLoginUser(request, response));
        Map map=super.getLoginUser(request, response);
        return new ModelAndView(new RedirectView("getNoticeList.do"), map);
    }

    /**
     * 进入私有推送页面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getPushMessageList.do")
    public ModelAndView getPushMessageList(HttpServletRequest request, HttpServletResponse response, Pagination pagination){

        ModelAndView model = new ModelAndView("/module/appInfM/messageInf/push_messageInf_list");
        return super.getDetail(request, response, model);
    }
    /**
     * 查询私有推送列表信息json数据
     * @param pagination
     * @param appMessageInfEntity
     * @return
     */
    @RequestMapping("/pushMessageListJson.do")
    public @ResponseBody
    Map getPushMessageListJson(HttpServletRequest request, Pagination pagination, App_Message_InfEntity appMessageInfEntity, App_Custom_InfEntity appCustomInfEntity){
        return messageInfService.getPushMessageList(request,pagination, appMessageInfEntity,appCustomInfEntity);
    }
    /**
     * 私有推送详细页面
     * @param request
     * @param response
     * @param pagination
     * @param message_uuid
     * @return
     */
    @RequestMapping("/getPushMessageDetail.do")
    public ModelAndView getPushMessageDetail(HttpServletRequest request, HttpServletResponse response,
                                        Pagination pagination,String message_uuid) {
        ModelAndView model = new ModelAndView("/module/appInfM/messageInf/push_messageInf_detail");
        // 菜单编码
        Map infEntity = messageInfService.getPushMessageById(message_uuid);
        model.addObject("infEntity", infEntity);
        return super.getDetail(request, response, model);
    }

    /**
     * 更新发布状态
     * @param request
     * @param response
     * @param message_uuids
     * @return
     */
    @RequestMapping("/updNoticeDetail.do")
    @ResponseBody
    public Map<String, Object> updNoticeDetail(HttpServletRequest request, HttpServletResponse response, String message_uuids, String publish_st ) {
        messageInfService.updNoticeDetail(message_uuids,publish_st, super.getLoginUser(request, response));
        return new HashMap<>();
    }
    /**
     * 获取会员上下级关系菜单树
     * @param ins_uuid
     * @return
     */
    @RequestMapping("/customerTree_show.do")
    @ResponseBody
    public List<Map<String, Object>> getCustomerRelationTree(HttpServletRequest request,String searchText){
        return messageInfService.getCustomerRelationTree(request,searchText);
    }
    /**
     * 保存推送信息
     * @param request
     * @param response
     * @param appMessageInfEntity
     * @return
     */
    @RequestMapping("/savePushMessageDetail.do")
    public ModelAndView savePushMessageDetail(HttpServletRequest request, HttpServletResponse response, App_Message_InfEntity appMessageInfEntity,String custom_uuid,String ins_uuid) {

        messageInfService.savePushMessage(appMessageInfEntity, super.getLoginUser(request, response),custom_uuid,ins_uuid);
        Map map=super.getLoginUser(request, response);
        return new ModelAndView(new RedirectView("getPushMessageList.do"), map);
    }
}
